* Purpose: Heterogeneity table, Appendix Table C11
do "D:\Data\workdata\708296\Project - Mother groups and mental health\Do\global.do" 

use "$work\final_data1", clear

gen pre = 0
foreach v in inp1y_pre out1y_pre gpmw_cons1y_pre gpmw_psyk1y_pre {
replace pre = 1 if `v' == 1	
}	
gen young = 1 if alder_m < 26
replace young = 0 if young == .

gen epds = 0
replace epds = 1 if score_e1 > 4 & score_e1 < 11
replace epds = . if score_e1 > 10 

capture erase "$out\heterotables_addoutcomes.tex"
file open myfile using  "$out\heterotables_addoutcomes.tex", write replace
file write myfile "   &\multicolumn{1}{c}{(Zero)}         &\multicolumn{1}{c}{(One)}         \\"
file write myfile "%outcomes consw24 psykw24 adm24; characteristics pre mfr_first young epds "
file close myfile
replace hospage1 = . if mfr_yob == 2017
foreach var in consw24 psykw24 adm24 sumhonorar1 hospage1{
foreach bvar of varlist pre mfr_first young epds{
	estimates clear
forvalues j = 0/1 {
areg `var' peer_treat if `bvar' == `j', absorb(time fe mfr_first) vce(cluster group)
estimates store p`bvar'`j'`var'
}
}
label var peer_treat "`var'"

esttab p* using "$out\heterotables_addoutcomes.tex", fragment b(3) se(3) keep(peer_treat)  se star(* 0.10 ** 0.05 *** 0.01) alignment(c c) label nolegend nonote  nodepvars nomtitles noobs eqlabel(none) append
}
* Note: Local formatting of output necessary

